package com.teatrace.commons.util;

import java.lang.reflect.Method;



public class DaoHelper {

	public static void setDeleted(Class clazz, Object obj, boolean deleted)
			throws Exception {
		try {
			clazz.getMethod("setDeleted", new Class[] { boolean.class }).invoke(
					obj, deleted);
		} catch (NoSuchMethodException e) {
			throw new UnsportedLogicDeleteEntityException("Entity:" + clazz.getName());
		}
	}
	
	public static Object getValue(Class clazz, Object obj, String propertyName) throws Exception {
		char [] charArray = propertyName.toCharArray();
		charArray[0] -= 32;
		String readMethodName = "get" + String.valueOf(charArray);
		Method method = clazz.getDeclaredMethod(readMethodName, new Class[0]);
		Object value = method.invoke(obj, new Object[0]);
		return value;
	}

}
